package com.xbongbong.saas.service.impl;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IEntity;
import com.xbongbong.pro.supplierproduct.pojo.SupplierProductDeleteBatchDTO;
import com.xbongbong.saas.domain.entity.SupplierProductEntity;
import com.xbongbong.saas.model.SupplierProductModel;
import com.xbongbong.saas.service.SupplierProductService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author WangJian
 * @date  2019-01-25 15:45
 **/
@Service("SupplierProductService")
public class SupplierProductServiceImpl implements SupplierProductService {

    @Resource
    private SupplierProductModel supplierProductModel;

    @Override
    public Integer insert(Object entity) throws XbbException {
        return supplierProductModel.insert((SupplierProductEntity) entity);
    }

    @Override
    public Integer update(Object entity) throws XbbException {
        return supplierProductModel.update((SupplierProductEntity) entity);
    }

    public Integer save(IEntity entity) throws XbbException {
        if (entity.getId() == null || Objects.equals(0, entity.getId())) {
            return supplierProductModel.insert((SupplierProductEntity) entity);
        }
        return supplierProductModel.update((SupplierProductEntity) entity);
    }

    public Integer deleteByKey(Long key, String corpid) {
        return supplierProductModel.deleteByKey(key, corpid);
    }

    public SupplierProductEntity getByKey(Long key, String corpid) {
        return supplierProductModel.getByKey(key, corpid);
    }

    @Override
    public List<SupplierProductEntity> findEntitys(Map<String, Object> param) {
        return supplierProductModel.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return supplierProductModel.getEntitysCount(param);
    }

    @Override
    public void deleteBySupplierId(SupplierProductDeleteBatchDTO supplierProductDeleteBatchDTO) throws XbbException {
        List<Long> supplierIdList = supplierProductDeleteBatchDTO.getSupplierIdList();
        if (supplierIdList != null && !supplierIdList.isEmpty()) {
            supplierProductModel.deleteBySupplierIdIn(supplierProductDeleteBatchDTO.getCorpid(), supplierIdList);
        }
    }

    @Override
    public void delBySupplierIdAndId(Long supplierId, Long productSubId, String corpid) {
        supplierProductModel.delBySupplierIdAndId(supplierId, productSubId, corpid);
    }
}
